package com.learn.transactional.controller;

import com.learn.transactional.dao.pojo.Student;
import com.learn.transactional.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class StudentController {
    @Resource
    private StudentService studentService;

    @RequestMapping("/addStudent")
    @ResponseBody
    public String addStudent(String name, Integer age){
        Student student = new Student();
        student.setName(name);
        student.setAge(age);
        int rows = studentService.addStudent(student);
        return "成功添加数据： " + rows;
    }

    @RequestMapping("/query")
    @ResponseBody
    public Student queryStudent(Integer id){
        Student student = studentService.queryStudent(id);
        return  student;
    }
}
